{% extends "base_tree.html" %}

{% block list %}
<h3>Категория {{ category.parent.parent.parent.name }}/{{ category.parent.parent.name }}/{{ category.parent.name }}/{{ category.name }}</h3>
<p style="padding-bottom: 8px">
<a href="{% url ktit.storage.views.categorys.edit currentcategory %}">Изменить</a> |
<a href="{% url ktit.storage.views.categorys.delete currentcategory %}">Удалить</a>
</p>

<h3>Нумерованные запчасти в документе прихода</h3>



<script type="text/javascript">
<!--

function setQuantity(value) {
  document.getElementById('id_quantity').value=value;
}//setQuantity


function addEvent(element,event,handler){
  if(element.addEventListener)
    element.addEventListener(event,handler,false);
  else if(element.attachEvent)
    element.attachEvent('on'+event,handler);
  else
    throw 'Can\'t add event';
}//addEvent


function getElementsByClass(value,scope,tag_name) {
	if(!scope)
		scope=document;
	if(!tag_name)
		tag_name='*';
	var els = scope.getElementsByTagName(tag_name);
  values=value.split(' ');
  class_res=[];
  for(var i=0;i<values.length;i++)
    class_res[class_res.length]=new RegExp('(^|\\s)'+values[i]+'($|\\s)');
  result=[];
  for(var i=0;i<els.length;i++) {
    var found=true;
    for(var j=0;j<class_res.length;j++)
      if(!els[i].className.match(class_res[j])){
        found=false;
        break;
      }//if
    if(found)
      result[result.length]=els[i];
  }//for
	return result;
}//getElementsByClass


function deleteTag(button){
  var li=button.parentNode;
  var ul=li.parentNode;
  //Prevent deletion of last input for it is used as a template for addition
  if(getElementsByClass('suggest_tag',li,'input').length && getElementsByClass('suggest_tag',ul,'input').length==1)
    addTag(ul.parentNode);
  ul.removeChild(li);
  var qnt=document.getElementById("id_quantity");
  qnt.value--;   
}//deleteTag
  
function addTag(tag_widget){
  var ul=tag_widget.getElementsByTagName('UL')[0];
  var lis=ul.getElementsByTagName('LI');
  var li=ul.appendChild(lis[lis.length-1].cloneNode(true));
  var input=li.getElementsByTagName('INPUT')[0];
  input.value='';
  //initAutoComplete(input,tag_widget);
  input.focus();
  var qnt=document.getElementById("id_quantity");
  qnt.value++; 
  //id_quantity
}//addTag
-->
</script>
<script type="text/javascript">
  addEvent(window, 'load', function() {setQuantity(1);});
</script>

<form action="." method="POST">
	<table align="left" cellpadding="2">
	{% for field in form %}<tr>
      <td>{% if field.help_text %}<p>{{ field.help_text }}</p>{% endif %}
	     {% if field.errors %}<p class="myerrors">{{ field.errors }}</p>{% endif %}</td>
      <td rowspan="2">{{ field }}</td>
    </tr>
    <tr>
      <td>{{ field.label_tag }}{% if field.field.required %}<font color="red">*</font>{% endif %}</td>
    </tr>{% endfor %}

<tr><td colspan="2"><h4>Серийные номера</h4></td></tr>
<tr><td colspan="2">
<div id="id_input_serial" class="tag_input_serial">
  
  <ul>
    <li class="input">
      <input type="text" name="input_serial" class="suggest_tag" autocomplete="off" maxlength="32" size="32" />
      <img src="{% load media %}{% media_prefix %}img/icon_delete.gif" alt="[-]" title="" onclick="deleteTag(this);" />
  </ul>
  <p><img src="{% media_prefix %}img/icon_add.gif" alt="[+]" title="" onclick="addTag(this.parentNode.parentNode);" /></p>
  
</div>
</td></tr>
<tr><td></td><td><input type="submit" value="Сохранить"></td></tr>
</table>
</form>



{% endblock %}
